import { defineStore } from 'pinia';

interface ConfigState {
  mode: string; // e.g. "1,2,7,3,4,5,6"
  modeDictText: string; // e.g. "护理MDT,护理服务,..."
  button: string;
  buttonDictText: string;
  service: string;
  serviceDictText: string;
}

export const useConfigStore = defineStore('config-store', {
  state: (): ConfigState => ({
    mode: '',
    modeDictText: '',
    button: '',
    buttonDictText: '',
    service: '',
    serviceDictText: ''
  }),
  getters: {
    modeList: state => (state.mode ? state.mode.split(',') : []),
    modeTextList: state => (state.modeDictText ? state.modeDictText.split(',') : []),
    buttonList: state => (state.button ? state.button.split(',') : []),
    buttonTextList: state => (state.buttonDictText ? state.buttonDictText.split(',') : []),
    serviceList: state => (state.service ? state.service.split(',') : []),
    serviceTextList: state => (state.serviceDictText ? state.serviceDictText.split(',') : [])
  },
  actions: {
    setFromRecord(record: any) {
      // console.log(record, 'record ##### 😂')
      this.mode = record?.mode || '';
      this.modeDictText = record?.mode_dictText || '';
      this.button = record?.button || '';
      this.buttonDictText = record?.button_dictText || '';
      this.service = record?.service || '';
      this.serviceDictText = record?.service_dictText || '';
    },
    reset() {
      this.$reset();
    }
  }
});


